k = 1000
a = [i for i in range(k + 1)]
a[1] = 0
i = 2
while i <= k ** 0.5:
    if a[i] != 0:
        j = i ** 2
        while j <= k:
            a[j] = 0
            j = j + i
    i += 1
a = [i for i in a if a[i] != 0]
d = {
    "zero": 0,
    "one": 1,
    "two": 2,
    "three": 3,
    "four": 4,
    "five": 5,
    "six": 6,
    "seven": 7,
    "eight": 8,
    "nine": 9
}
b = d.keys()
c = input().split()
for i in c:
    if i not in b:
        print("Wrong input")
        exit()
e = d[c[0]] * 100 + d[c[1]] * 10 + d[c[2]]
if e < 100:
    print("Wrong input")
    exit()
if e in a:
    print(e)
    exit()
a.insert(0, e)
a.sort()
print(a[a.index(e) - 1] if abs(e - a[a.index(e) - 1]) < abs(e - a[a.index(e) + 1]) else a[a.index(e) + 1])
